﻿/* --------------------------------------------------------------------------------------------------------------------
// <copyright file="EnhancedNew.js" company="Lambros Vasiliou">
//   © 2013
// </copyright>
// <summary>
//   JavaScript methods for Enhanced New Dialog.
// </summary>
// --------------------------------------------------------------------------------------------------------------------*/

/* <summary>
//   Displays the enhanced new dialog.
// </summary>*/
function showEnhancedNew() {
    var rootFolder = getQuerystring("RootFolder");
     
    var options = SP.UI.$create_DialogOptions();
    options.url = this._spPageContextInfo.webAbsoluteUrl + "/_layouts/15/EnhancedNew.aspx?ListId=" + SP.ListOperation.Selection.getSelectedList() + "&rootFolder=" + rootFolder;
    options.autoSize = true;
    options.width = 640;
    options.showClose = true;
    options.allowMaximize = true;
    this.dialog = SP.UI.ModalDialog.showModalDialog(options);
}

/* <summary>
//   Extracts values from query string parameters.
// </summary>
// <param name="key">They key of the query string parameter for which the value is to be retrieved.</param>*/
function getQuerystring(key) {
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return "";
    else
        return qs[1];
}